package com.geo.result.controller;

import com.geo.result.domain.TOrderItems;
import com.geo.result.service.ITOrderItemsService;
import com.sino.common.core.utils.poi.ExcelUtil;
import com.sino.common.core.web.controller.BaseController;
import com.sino.common.core.web.domain.AjaxResult;
import com.sino.common.core.web.page.TableDataInfo;
import com.sino.common.log.annotation.Log;
import com.sino.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/orderitems")
public class TOrderItemsController  extends BaseController {

    @Autowired
    private ITOrderItemsService tOrderItemsService;

    /**
     * 查询资料申请单列表
     */
    @PreAuthorize("@ss.hasPermi('result:materi:list')")
    @GetMapping("/list")
    public TableDataInfo list(TOrderItems tOrderItems)
    {
        startPage();
        List<TOrderItems> list = tOrderItemsService.selectTOrderItemsList(tOrderItems);
        return getDataTable(list);
    }

    /**
     * 导出测试样例列表
     */
    @PreAuthorize("@ss.hasPermi('result:materi:export')")
    @Log(title = "资料申请单明细表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody TOrderItems tOrderItems) throws IOException
    {
        List<TOrderItems> list = tOrderItemsService.selectTOrderItemsList(tOrderItems);
        ExcelUtil<TOrderItems> util = new ExcelUtil<TOrderItems>(TOrderItems.class);
        util.exportExcel(response, list, "materi");
    }

    /**
     * 获取资料申请单详细信息
     */
    @PreAuthorize("@ss.hasPermi('result:materi:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(tOrderItemsService.selectTOrderItemsByGuid(guid));
    }

    /**
     * 新增测试样例
     */
    @PreAuthorize("@ss.hasPermi('result:materi:add')")
    @Log(title = "资料申请单明细表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TOrderItems tOrderItems)
    {
        return toAjax(tOrderItemsService.insertTOrderItems(tOrderItems));
    }

    /**
     * 修改测试样例
     */
    @PreAuthorize("@ss.hasPermi('result:materi:edit')")
    @Log(title = "资料申请单明细表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TOrderItems tOrderItems)
    {
        return toAjax(tOrderItemsService.updateTOrderItems(tOrderItems));
    }

    /**
     * 删除测试样例
     */
    @PreAuthorize("@ss.hasPermi('result:materi:remove')")
    @Log(title = "资料申请单明细表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(tOrderItemsService.deleteTOrderItemsByGuids(guids));
    }

}
